package com.rst.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.rst.model.Attendance;
import com.rst.model.Classe;

@Repository
@Transactional
public class AttendanceDAO {

	@Autowired
	private static SessionFactory sessionFactory;


	public void udateClass(Classe class1) {
		sessionFactory.getCurrentSession().update(class1);
	}

	@SuppressWarnings("unchecked")
	public List<Classe> getClassList() {
		Session session = sessionFactory.getCurrentSession();
	    String str = "FROM Class c ORDER BY c.name";

	    Query query = session.createQuery(str);
		return query.list();
		}

	public Long saveAttendance(Attendance attendance) {
		return (Long) sessionFactory.getCurrentSession().save(attendance);
		}

	public Attendance getAttendanceById(Long attendanceId) {
		Session session = sessionFactory.getCurrentSession();
		Attendance attendance = (Attendance)session.get(Attendance.class, attendanceId);
		return attendance;
	}


}
